package com.ncu702.backend.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ncu702.backend.mapper.ArticleMapper;
import com.ncu702.backend.mapper.RewardMapper;
import com.ncu702.backend.model.dto.articles.ArticleVo;
import com.ncu702.backend.model.entity.Article;
import com.ncu702.backend.service.ArticleService;
import com.ncu702.backend.service.RewardService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class RewardServiceImpl extends ServiceImpl<RewardMapper, Article> implements RewardService {

    @Resource
    RewardMapper rewardMapper;

    @Override
    public List<ArticleVo> getAllReward() {
        List<ArticleVo> articles=rewardMapper.getAllReward();
        return  articles;
    }

    @Override
    public Integer addReward(String articleId,Integer money) {
        UpdateWrapper<Article> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("help", money).eq("article_id", articleId);
        return rewardMapper.update(null, updateWrapper);
    }

    @Override
    public Integer deleteReward(String articleId) {
        UpdateWrapper<Article> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("help", 0).eq("article_id", articleId);
        return rewardMapper.update(null, updateWrapper);
    }
}
